package com.springinaction.soundsystem;

import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TrackCounter {
	private Map<Integer,Integer> trackCount = new HashMap<Integer,Integer>();
	
	@Pointcut("execution(* com.springinaction.soundsystem.CompactDisc.play(String)) && args(num)")
	public void trackPlayed(int num){}
	
	@Before("trackPlayed(num)")
	public void countTrack(int num){
		int currentCount = getPlayCount(num);
		trackCount.put(num, currentCount+1);
		System.out.println(num);
	}

	public int getPlayCount(int num) {
		return trackCount.containsKey(num)?trackCount.get(num):0;
	}

	
}
